using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Diagnostics;

namespace TXLooker.WorkItemExtention.Core
{
    class XmlViewParser
    {
        private const string Heading    = "heading";
        private const string Column     = "column";
        private const string Width      = "width";
        private const string Categories = "Categories";
        private string m_xmlString;
        private List<string> m_columnName = new List<string>();

        private XmlViewParser()
        { }

        public XmlViewParser(string xmlString)
        {
            this.m_xmlString = xmlString;

            ParseColumns();
        }

        private void ParseColumns()
        {
            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(this.m_xmlString);

                XmlNodeList columns = xmlDocument.GetElementsByTagName(Column);
                foreach (XmlNode xmlNode in columns)
                {
                    if (!xmlNode.HasChildNodes)
                        continue;
                    foreach (XmlNode node in xmlNode.ChildNodes)
                    {
                        if (node.Name == Heading && node.InnerText != Categories)
                            this.m_columnName.Add(node.InnerText);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error in ParseColumns " + ex.ToString());
            }
        }

        public List<string> Columns
        {
            get { return m_columnName; }
        }
    }
}
